//具体业务接口
import {postApi, getApi,uploadFile} from '@/common/js/config.js'

// 获取手机验证码 event register 注册 mobilelogin：短信登录
const getPhoneCode = (mobile, event)=>{
	return postApi("/api.php/sms/send", {mobile, event}) 
}
const userRegister = (params)=>{
	return postApi("/api.php/user/register", params)
}
// 用户账号密码登陆
const userLogin = (params)=>{
	return postApi("/api.php/user/login", params)
}
// 用户手机验证码登录  mobile, captcha
const phoneLogin = (params)=>{
	return postApi("/api.php/user/mobilelogin", params)
}
//获取用户信息
const getUserInfo = ()=>{
	return getApi("/api.php/index/getUserInfo")
}
// 获取新闻列表
const getNewsList = ()=>{
	return getApi("/api.php/index/getNews")
}
// 获取新闻详情
const getNewsDetails = (id)=>{
	return getApi(`/api.php/index/newsDetail?id=${id}`)
}
// 获取首页、对应市场的热门股票列表
const getHotStock = (id=0)=>{
	return getApi(`/api.php/index/getHotGupiaoList?classify_id=${id}`)
}
// 獲取地区分類
const getAreaCate = ()=>{
	return getApi(`/api.php/common/getClassIfy`)
}
// 获取自选股票列表
const getOptionalList = (cateId)=>{
	return getApi(`/api.php/index/getZixuan?classify_id=${cateId}`)
}
// 获取市场股票列表
const getMarketList = (cateId, page, file='', order='')=>{
	return getApi(`/api.php/index/getGupiaoList?classify_id=${cateId}&page=${page}&file=${file}&order=${order}`)
}

// 搜索股票代码
const queryStockCode = (code, cate="")=>{
	// return getApi(`/api.php/index/Search?key_word=${code}`)
	return getApi(`/api.php/index/getGupiaoList?key_word=${code}&classify_id=${cate}&page=1`)
}
// 获取股票详情
/* 
 name 名字  shuzidaima编码数字 price价格  涨跌幅  zhangdiebaifenbi
 open  开盘价
 close 昨日收盘价   high最高价     low最低价   vol成交量    turnover成交额
*/
const getStockDetail = (id)=>{
	return getApi(`/api.php/index/getGupiaoDetail?id=${id}`)
}
// 获取行情指数
const getMarketIndex = (id)=>{
	return getApi(`/api.php/index/getZhishu?classify_id=${id}`)
}
// 获取IPO列表
const getIPOList = (id, type)=>{
	return getApi(`/api.php/index/getXingu?category_id=${id}&type=${type}`)
}
// 獲取當股票添加自選的狀態
const getOptionalStatus = (id)=>{
	return getApi(`/api.php/index/isZixuan?id=${id}`)
}
// 添加自選 取消自选 
const addOrDelOptional = (id)=>{
	return postApi(`/api.php/index/addZixuan`, {id})
}
// ipo认购
const ipoBuy = (params)=>{
	return postApi(`/api.php/index/shengouXingu`, params)
}
// 获取用户开户信息
const getUserOpenInfo = ()=>{
	return postApi(`/api.php/user/getRealname`)
}
// 提交开户信息
const subOpenInfo = (params)=>{
	return postApi(`/api.php/user/subRealname`, params)
}
// 获取用户银行卡列表
const getUserBankCards = ()=>{
	return getApi(`/api.php/index/getBankList`)
}
// 添加银行卡
const addBankCard = (params)=>{
	return postApi(`/api.php/index/setUserInfo`, params)
}
// 获取交易记录
const getTradeRecords = (status,page)=>{
	return getApi(`/api.php/index/getChicangLog?status=${status}&page=${page}`)
}
// 获取持仓记录
const getPosRecords = (id)=>{
	return getApi(`/api.php/index/getJiaoyi?classify_id=${id}`)
}
// 获取资金记录 
const getFundRecords = (type=3)=>{
	return getApi(`/api.php/index/getLiuShui?type=${type}`)
}
// 获取入金信息
const getRechargeInfo = (id)=>{
	return getApi(`/api.php/index/getRechargeInfo?classify_id=${id}`)
}
// 提交入金信息
const subRechargeInfo = (params)=>{
	return postApi(`/api.php/index/addRecharge`, params)
}
// 获取出金信息
const getWithdrawaInfo = (id)=>{
	return getApi(`/api.php/index/getWithdrawaInfo?category_id=${id}`)
}
// 提交出金操作
const subWithdrawal = (params)=>{
	return postApi(`/api.php/index/submitWithdrawal`, params)
}
// 上传图片
const uploadImg = (file)=>{
	return uploadFile("/api.php/common/upload", file)
}
// 修改密码
const resetPwd = (params)=>{
	return postApi(`/api.php/user/resetpwd`, params)
}
// 買賣股票
const buySellStock = (params)=>{
	return postApi(`/api.php/index/buyGupiao`, params)
}
const chuli = (params)=>{
	return postApi(`/api.php/user/chuli`, params)
}

// 删除自选
const deleteOptional = (id)=>{
	return postApi(`/api.php/index/delZixuan`, {id}) 
}
// 获取盘口数据
const getHandicapList = (id)=>{
	return getApi(`/api.php/user/pankou?id=${id}`)
}
const gupiaoDetail = (id)=>{
	return getApi(`/api.php/user/getGupiaoDetail?id=${id}`)
}

// 获取成交数据
const getDealRecords = (id)=>{
	return postApi(`/api.php/user/newCreate`, {id})
}
// 获取配置信息
const getConfigInfo =()=>{
	return getApi(`/api.php/index/getConfig?id=3`)
}


const search = (q)=>{
	return getApi(`/api.php/index/searcha?q=${q}`)
}


// 获取消息记录
const getMsgList = ()=>{
	return getApi(`/api.php/user/userMoneyLog`)
}
const getConfig = ()=>{
	return getApi(`/api.php/common/getConfig`)
}

// 兌換金額
const exChangeHandle = (params)=>{
	return postApi(`/api.php/user/fund_conversion`, params)
}
// 兑换记录
const getExchangeRecords = ()=>{
	return getApi(`/api.php/user/fund_conversion_log`)
}
//  申购记录
const getApplyBuyRecords = ()=>{
	return getApi(`/api.php/user/shengoulog`)
}
const getChiCangApply = (classify_id,type) => {
	return getApi(`/api.php/index/getJiaoyi?classify_id=${classify_id}&type=${type}`)
}

const leverage = (classify_id,checked) => {
	return getApi(`/api.php/user/leverage?classify_id=${classify_id}&checked=${checked}`)
}

// 获取K线数据
const getKeyLine = (id, timer)=>{
	return getApi(`/api.php/user/klne?pro_id=${id}&interval=${timer}`)
}
//获取兑换huilv
const getExchangeRate = (from, to)=>{
	return getApi(`/api.php/index/huilv?from=${from}&to=${to}`)
}
// 获取推荐二维码
const getUserQrCode = ()=>{
	return getApi(`/api.php/user/getCode`)
}
//上传用户头像
const updateUserAvatar = (avatar)=>{
	return postApi("/api.php/user/profile", {avatar})
}
const inMoneyhistory = (type) => {
	return getApi(`/api.php/index/getLiuShui?type=${type}`)
}
const outMoneyhistory = (type) => {
	return getApi(`/api.php/index/getLiuShui?type=${type}`)
}
export default{
	inMoneyhistory,
	outMoneyhistory,
	getChiCangApply,
	getPhoneCode,
	leverage,
	phoneLogin,
	userRegister,
	userLogin,
	getUserInfo,
	getNewsList,
	getNewsDetails,
	getHotStock,
	getAreaCate,
	getOptionalList,
	getMarketList,
	getTradeRecords,
	getFundRecords,
	queryStockCode,
	getStockDetail,
	getMarketIndex,
	getIPOList,
	addOrDelOptional,
	getOptionalStatus,
	ipoBuy,
	getUserOpenInfo,
	subOpenInfo,
	getUserBankCards,
	addBankCard,
	getPosRecords,
	getRechargeInfo,
	subRechargeInfo,
	getWithdrawaInfo,
	subWithdrawal,
	uploadImg,
	resetPwd,
	buySellStock,
	deleteOptional,
	getHandicapList,
	chuli,
	gupiaoDetail,
	getDealRecords,
	getConfigInfo,
	search,
	getMsgList,
	getConfig,
	exChangeHandle,
	getExchangeRecords,
	getApplyBuyRecords,
	getKeyLine,
	getExchangeRate,
	getUserQrCode,
	updateUserAvatar
}